package com.gushenge.core.base.activity

import android.annotation.SuppressLint
import android.content.Context
import android.content.res.Configuration
import android.content.res.Resources
import android.os.Bundle
import android.os.Looper
import androidx.appcompat.app.AppCompatActivity
import com.gushenge.atools.util.AView
import com.hjq.language.MultiLanguages
import me.jessyan.autosize.AutoSizeCompat


@SuppressLint("Registered")
open class BaseActivity:AppCompatActivity()  {
    override fun attachBaseContext(newBase: Context?) {
        // 绑定语种
        super.attachBaseContext(MultiLanguages.attach(newBase))
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        AView.setStatusBar(this@BaseActivity, true)
        resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT
    }

    override fun getResources(): Resources {
        val resources = super.getResources()
        try {
            val configuration = Configuration()
            configuration.setToDefaults()
            resources?.updateConfiguration(configuration, resources.displayMetrics)
            AutoSizeCompat.autoConvertDensityOfGlobal(resources)
            if (Looper.myLooper() == Looper.getMainLooper()) {
                AutoSizeCompat.autoConvertDensity(
                    resources,
                    375.toFloat(),
                    resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT
                )
            }
        } catch (e: Exception) {
        } finally {
            return resources
        }
        return resources

    }
}